﻿<%@ page language="java" import="net.sf.json.JSONArray,com.newcrm.config.Const,com.newcrm.util.Util,com.newcrm.bean.*,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  User user = (User) session.getAttribute("user");
  int successNum = Util.str2Int(request.getAttribute("successNum"));
  int existNum = Util.str2Int(request.getAttribute("existNum"));
  String existCustomerIds = (String)request.getAttribute("existCustomerIds");
  if (existCustomerIds == null) {
    existCustomerIds = "";
  }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>客户导入结果</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/all.css?ver=<%=Const.VERSION%>">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/datepicker.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap-datetimepicker.min.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/magnific-popup.css">
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-ui.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.bootstrap-growl.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/daterangepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.magnific-popup.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.cookie.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/popbox.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/common.js?ver=<%=Const.VERSION%>"></script>
  <script>
    $(function() {
      $("#partiesMenu").addClass("selected");
      $("#navi-1").show();
      $("#tabs a").click(function(e) {
        e.preventDefault();
        $("#tabs li").removeClass("active");
        $(this).parent().addClass("active");
        $(".tab-container").hide();
        $($(this).attr("href")).show();
      });
      <% if (existNum > 0) {%>
      var _existCustomerIds = $("a.existCustomer").map(function() {
            return $(this).attr("v");
          }).get().join();
      var params = {};
      params.isFromImport = "1";
      params.ids = _existCustomerIds;
      $.ajax({
        url: contextPath + '/companyName?operation=list&random=' + Math.random(),
        type: 'POST',
        contentType: 'application/x-www-form-urlencoded; charset=utf-8',
        data:params,
        dataType: 'json',
        timeout: 60000,
        error: function(){
        },
        success: function(json) {
          if (json.error == "2") {
            $.bootstrapGrowl("登陆超时，请重新登陆");
            window.location = contextPath + "/signin";
            return;
          }
          if (json.error == "1") {
            $.bootstrapGrowl("加载导入重复客户信息失败");
            return;
          }
          $.each(json.items, function(idx,item) {
            $("#existCustomer_" + item.CustomerId).text(item.Name);
          });
        }
      });
      <%}%>
    });
  </script>
</head>
<body class="parties former_sheet">
  <jsp:include page="topNavi.jsp" flush="true"/>
  <div class="main-page">
    <table>
    <tr>
      <td class="main-body">
        <div class="topnavi"><div class="leftMenu"><span>导入客户信息</span></div></div>
        <div class="searchresult">
          <div class="col">
            <div class="innercol">
              <div class="profile-info-tabs">
                <ul class="nav-tabs" id="tabs">
                  <li class="active"><a href="#navi-1">导入新客户 <%=successNum%> 条</a></li>
                  <li><a href="#navi-2">处理已存在客户 <%=existNum%> 条</a></li>
                </ul>
                <div class="nav-detail">
                  <div id="navi-1" class="tab-container body setting-panel">
<%if (successNum == 0) { %>
                    <h1>没有导入成功的新客户</h1>
                    <p class="submit">
                      <a href="<%=request.getContextPath()%>/customerimports/new" class="button blue"><i class="fa fa-reply"></i> 重新导入</a>
                    </p>
<%} else {%>
                    <h1>以下为导入的数据的前 5 条（仅列出联系人信息，导入公司确认请通过【查看导入客户】）</h1>
                    <table class="index">
<%
  List<CustomerInfo> sampleItems = (List<CustomerInfo>) request.getAttribute("sampleItems");
  if (sampleItems != null) {
      for (CustomerInfo info:sampleItems) {%>
                    <tr>
                    <td class="avatar">
                      <a href="<%=request.getContextPath()%>/people/<%=info.id%>" class="image"><img src="<%=request.getContextPath()%>/images/avatar_person.png" class='avatar' height='55'></a>
                    </td>
                    <td class="party">
                      <div class="avatar_subject">
                        <div class="info">
                          <h3 ><a href="<%=request.getContextPath()%>/people/<%=info.id%>" class="to_person"><%=Util.HTMLEncode(info.name)%></a></h3>
                          <h6><div class="title_and_company"><a href="<%=request.getContextPath()%>/company/<%=info.parentId%>"><%=Util.HTMLEncode(info.parentName)%></a></div></h6>
                        </div>
                      </div>
                    </td>
                    </tr>
<%}}%>
                    </table>
                    <p class="submit">
                      <a href="<%=request.getContextPath()%>/parties?importId=<%=request.getAttribute("importId")%>" class="button blue"><i class="fa fa-check"></i> 查看导入客户</a>
<% if (user.isCanDelete()) {%><a href="<%=request.getContextPath()%>/customerimports/<%=request.getAttribute("importId")%>/undo" class="button red"><i class="fa fa-times"></i> 删除所有导入的数据</a><%}%>
                    </p>
<%}%>
                  </div>
                  <div id="navi-2" class="tab-container body setting-panel">
<%if (existNum == 0) { %>
                    <h1>没有重复的客户</h1>
<%} else {%>
                    <h1>以下为处理已存在客户数据的前 100 条</h1>
                    <p class="tips"># 说明：如果导入客户为已存在客户，客户分类等基本信息不变，系统将自动判断导入客户的属性字段：</p>
                    <p class="tips"><font color="red"> 对系统定义字段，不重复的值将被更新，重复的自动跳过。例如电话号码，如果有新加号码，将自动插入，如果重复，则跳过。</font></p>
                    <p class="tips"><font color="red"> 对客户自定字段，系统直接以导入数据覆盖原有值。</font></p>
                    <table class="index">
<%
  String[] arrExistCustomerIds = existCustomerIds.split(",");
  for (int i = 0; i < arrExistCustomerIds.length; i++) {
  if (i >= 100) {
    break;
  }
  %>
                <tr><td><a target="_blank" class="existCustomer" id="existCustomer_<%=arrExistCustomerIds[i]%>" v="<%=arrExistCustomerIds[i]%>"><%=arrExistCustomerIds[i]%></a></td></tr>
<%}%>
                </table>
<%}%>
                </div>
              </div>
            </div>
          </div>
        </div>
      </td>
    </tr>
    </table>
  </div>
</body>
</html>